package com.d4a5.mapping.google2
{
	import com.d4a5.mapping.core.AmfFactory;
	import com.d4a5.mapping.core.AmfObject;
	import com.google.maps.overlays.PolygonOptions;
	import com.google.maps.overlays.PolylineOptions;
	import com.google.maps.styles.StrokeStyle;
	
	import flash.geom.Matrix;
	
	public class wmgOverlayLayerPolyline extends wmgOverlayLayerBaseShape
	{
		public function wmgOverlayLayerPolyline(geometry:Object,options:PolylineOptions)
		{
			var amf:AmfObject;
			if( geometry is AmfObject ){
				amf = geometry as AmfObject;
			}
			else if( geometry is Array ){
				amf = AmfFactory.Create( AmfFactory.formatGoogle , AmfFactory.typePolyline , geometry as Array , null );
			}
			 
			super(amf);
			
			this.setOptions( ( options )? PolylineOptions.merge( [options,PolylineOptions.getDefaultOptions()] ) : PolylineOptions.getDefaultOptions());
		}
		
		override protected function __redraw(m:Matrix):void {
			this.graphics.clear();
			this._drawn = false;
			
			var options:PolylineOptions = this.getOptions() as PolylineOptions;
			var stroke:StrokeStyle = options.strokeStyle;
			//this.toolTip = options;
			
			if( stroke && stroke.alpha > 0 && stroke.thickness > 0 ){
				this.graphics.lineStyle( stroke.thickness as Number, stroke.color as uint , stroke.alpha as Number , stroke.pixelHinting );
				amf.drawRingsOnGraphicsNoTranslation( this.graphics , m );
				this._drawn = true;
			}
		}
		
		override public function setOptions(o:Object):void {
			if( o is PolylineOptions && this._options != o ){
				this._options = o;
				if( this._isAdded ){
					this.redraw();
				}
			}
		}
		
		
		override public function getDefaultOptions() : Object {
			return PolylineOptions.getDefaultOptions();
		}
		override public function mergeOptions( toBeMerged:Array ) : Object {
			return PolylineOptions.merge( toBeMerged );
		}
		
		override public function updateGeometry( geometry:Object ) : void { 
			var amf:AmfObject;
			if( geometry is AmfObject ){
				amf = geometry as AmfObject;
			}
			else if( geometry is Array ){
				amf = AmfFactory.Create( AmfFactory.formatGoogle , AmfFactory.typePolyline , geometry as Array , null );
			}
			
			this.updateAmf( amf );
		}
		
		override public function generalizeAmf( coordsMatrix:Matrix , generalizePixelCount:uint = 2 ) : void {
			this.amf.generalizeRings( coordsMatrix , generalizePixelCount , false );
		}
	}
}